package com.kura.uednews.fragment;

import com.kura.uedews.R;
import com.kura.uednews.MainActivity;
import com.kura.uednews.db.newsDB;

import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

public class fragment_todo_item extends Fragment {
	
	EditText todonameEdt;
	Button huyBtn;
	Button luuBtn;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		return inflater.inflate(R.layout.fragment_todo_item, container, false);
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		
		//get instance
		todonameEdt = (EditText) getActivity().findViewById(R.id.todonameEditText);
		
		
		//get instance
		huyBtn = (Button) getActivity().findViewById(R.id.huyBtn);
		
		//set event
		huyBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				FragmentTransaction tx = getFragmentManager()
						.beginTransaction();
				tx.replace(R.id.main, android.app.Fragment.instantiate(
						getActivity(),
						"com.kura.uednews.fragment.fragment_todo_list"));
				tx.commit();
			}
		});
		
		//get instance
		luuBtn = (Button) getActivity().findViewById(R.id.luuBtn);
		
		//set event
		luuBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				newsDB db = new newsDB(getActivity());
				db.addToDoItem(todonameEdt.getText().toString());
				FragmentTransaction tx = getFragmentManager()
						.beginTransaction();
				tx.replace(R.id.main, android.app.Fragment.instantiate(
						getActivity(),
						"com.kura.uednews.fragment.fragment_todo_list"));
				tx.commit();
			}
		});
	}
}
